package cn.fldong.employee.dao;

import cn.fldong.employee.entity.EmployeeEntity;
import cn.fldong.employee.entity.UserEntity;

import java.sql.ResultSet;

public class UserDao {
    public UserEntity queryUserByUsername(String username ) {
        DBUtil dao=new DBUtil();
        String sql="select * FROM userinfo WHERE username=? ";
        ResultSet resultSet=dao.executeQuery(sql,new String[]{ username });
        try {
            if(resultSet.next()){
                //empPass,empName, empGender, empAge, empDepartment, empPosition, empHireDate, empSalary
                UserEntity user=new UserEntity();
                user.setId(resultSet.getString("id"));
                user.setUsername(resultSet.getString("username"));
                user.setPassword(resultSet.getString("password"));
                return user;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            dao.closeConnection();
        }
        return null ;
    }
}
